<template>
	<view class="sortList">
		<goodsFilter :filters="goodsFilters" @sortChanged="goodsFilterChanged" @shapeChanged="goodsTemplateChanged" :showShape="false"/>
		<!-- 商品列表 -->
		<view class="goods-list">
			<view class="product-list">
				<view class="product" v-for="(goods,index) in contentList" :key="index" @tap="toGoods(goods)">
					<!-- <image mode="widthFix" :src="goods.pic"></image> -->
					<image mode="widthFix" src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2716688360,1326705556&fm=27&gp=0.jpg"></image>
					<view class="name">{{goods.title}}</view>
					<view class="info">
						<view class="tag">{{goods.tag}}</view>
						<view class="slogan">{{goods.author}}</view>
					</view>
				</view>
			</view>
			<view class="loading-text">{{loadingText}}</view>
		</view>
	</view>
</template>

<script>
	import goodsFilter from '@/components/filter/index.vue';
	import {
		recommendedList
	} from '@/apis/index.js';
	export default {
		components: {goodsFilter},
		data() {
			return {
				goodsFilters:[ {title:'默认排序',value:2,filterType:0}, {title:'按销量',value:4,filterType:1}, {title:'按时间',value:5,filterType:1,initAscState:true}],
			contentList: [],
			loadingText: "正在加载...",
			}
		},
		onLoad() {

		},
		mounted() {
			this.getRecommendList();
		},
		methods: {
			goodsFilterChanged(e){
				console.log("--------------goodsFilterChanged-------------------",e)
			},
			goodsTemplateChanged(e){
				console.log("--------------goodsTemplateChanged-------------------",e)
			},
			getRecommendList() {
				recommendedList({
					currentPage: 1,
					perPage: 10
				}).then(res => {
					let [err, data] = res;
					for (const arr of data.data.data) {
						let arrData = {}
						let tagsData = []
						let obj = JSON.parse(arr.tags);
						for (let i in obj) {
							tagsData.push(obj[i])
						}
						arrData.tag = tagsData[0]
						// this.contentList.pic=arr.pic
						arrData.title = arr.title
						arrData.author = arr.author
						this.contentList.push(arrData)
					}
				})
			},
			toGoods(goods) {
				uni.navigateTo({
					url: '/pages/index/detail'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import '@/components/filter/css/graceUI.css';
 @import '@/components/filter/css/main.css';
 @import '@/components/filter/css/icon.css';
 .sortList{
	 .goods-list {
	 	padding-top: 10px;
	 	background: #F4F4F4;
	 
	 	.loading-text {
	 		width: 100%;
	 		display: flex;
	 		justify-content: center;
	 		align-items: center;
	 		height: 30px;
	 		color: #979797;
	 		font-size: 12px;
	 	}
	 
	 	.product-list {
	 		width: 92%;
	 		padding: 0 4% 3vw 4%;
	 		display: flex;
	 		justify-content: space-between;
	 		flex-wrap: wrap;
	 
	 		.product {
	 			width: 48%;
	 			border-radius: 5px;
	 			background-color: #fff;
	 			margin: 0 0 7px 0;
	 			box-shadow: 0 3px 12px rgba(0, 0, 0, 0.1);
	 
	 			image {
	 				width: 100%;
	 				height: 70px;
	 				border-radius: 5px 5px 0 0;
	 			}
	 
	 			.name {
	 				width: 92%;
	 				padding: 5px 4%;
	 				display: -webkit-box;
	 				-webkit-box-orient: vertical;
	 				-webkit-line-clamp: 2;
	 				text-align: justify;
	 				overflow: hidden;
	 				font-size: 11px;
	 				height: 28px;
	 			}
	 
	 			.info {
	 				display: flex;
	 				justify-content: space-between;
	 				align-items: flex-end;
	 				width: 92%;
	 				padding: 5px 4% 5px 4%;
	 				font-size: 9px;
	 				color: #757575;
	 			}
	 		}
	 
	 	}
	 }
 }
</style>
